//
//  SecondViewController.m
//  07-UIDelegate-Block
//
//  Created by dllo on 16/7/22.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "SecondViewController.h"
#import "FirstViewController.h"

@interface SecondViewController ()
@property (nonatomic, strong)UITextField *textField;
@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.navigationController.navigationBar.translucent = NO;
//    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
    self.textField.backgroundColor = [UIColor yellowColor];
    self.textField.text = _titleString;
    [self.view addSubview:self.textField];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(0, 100, 300, 50);
    [button addTarget:self action:@selector(comeBack:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"返回上一页" forState:UIControlStateNormal];
    [self.view addSubview:button];
   //界面通信
   //1.属性传值， 一般常用于 从前往后传值
   // 将想要传递的值， 作为后一个页面的属性， 并通过该属性进行一系列的操作
  //  将FirstViewController 的titleLabel.text传递给SecondViewController 的textField
//        ⬇️ push               ⬇️ 属性传值
  // SecondViewController －》 titleString －》 去使用titleString做任意事情
}
- (void)comeBack:(UIButton *)button {
//    NSInteger count = self.navigationController.viewControllers.count;
//  FirstViewController *first = self.navigationController.viewControllers[count - 2];
//    first.titletextField = _textField.text;
#warning 触发协议方法  （判断代理人delegate存不存在， 判断签订delegate的类有没有实现协议方法）
    if (self.delegate && [self.delegate respondsToSelector:@selector(passValue:)]) {
        [self.delegate passValue:_textField.text];
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
